package com.md24housecall.fibromyalgiadiagnostic;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class IntroductionFragment extends Fragment {
    final static String ARG_POSITION = "position";
    int mCurrentPosition = -1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) {

        // If activity recreated (such as from screen rotate), restore
        // the previous article selection set by onSaveInstanceState().
        // This is primarily necessary when in the two-pane layout.
        if (savedInstanceState != null) {
            mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
        }
        
        
        
        
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.introduction_fragment, container, false);
        
        TextViewEx txtViewEx = (TextViewEx) view.findViewById(R.id.textViewEx);
        Resources res = getResources();
        String text = res.getString(R.string.introduction_text);
        txtViewEx.setText(text, true); 
        
        Button button = (Button) view.findViewById(R.id.next_button);
        button.setOnClickListener((OnClickListener) new ButtonEvent());
		return view;
    }

    private class ButtonEvent implements OnClickListener{

        @Override
        public void onClick(View v) {
        	NoticeFragment newFragment = new NoticeFragment();
            Bundle args = new Bundle();
            //args.putInt(NoticeFragment.ARG_POSITION, position);
            newFragment.setArguments(args);
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.setCustomAnimations(R.anim.in_from_right, R.anim.out_to_left, R.anim.in_from_left, R.anim.out_to_right);

            transaction.replace(R.id.fragment_container, newFragment);
            transaction.addToBackStack(null).commit();

        }

    }
    
    @Override
    public void onStart() {
        super.onStart();

        // During startup, check if there are arguments passed to the fragment.
        // onStart is a good place to do this because the layout has already been
        // applied to the fragment at this point so we can safely call the method
        // below that sets the article text.
        Bundle args = getArguments();
        if (args != null) {
            // Set article based on argument passed in
           // updateArticleView(args.getInt(ARG_POSITION));
        } else if (mCurrentPosition != -1) {
            // Set article based on saved instance state defined during onCreateView
            //updateArticleView(mCurrentPosition);
        }
    }

   
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        // Save the current article selection in case we need to recreate the fragment
        outState.putInt(ARG_POSITION, mCurrentPosition);
    }
}